<template>
  <div class="not-found-container">
    <div class="not-found-content">
      <div class="error-code">404</div>
      <h2 class="title">页面走丢啦~</h2>
      <p class="desc">您访问的页面不存在或已被删除，请检查访问地址是否正确</p>
      <div class="btn-group">
        <el-button type="primary" @click="goBack">返回上一页</el-button>
        <el-button @click="goHome">返回首页</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter, useRoute } from 'vue-router'
import { useUserStore } from '@/stores/modules/user'

const router = useRouter()
const route = useRoute()
const userStore = useUserStore()

// 返回上一页
const goBack = () => {
  router.go(-1)
}

// 返回对应角色首页（未登录则跳登录页）
const goHome = () => {
  if (!userStore.isLogin) {
    router.push('/login')
    return
  }

  const role = userStore.role
  if (role === 'super_admin') {
    router.push('/super-admin/user-manage')
  } else if (role === 'merchant') {
    router.push('/merchant/product-manage')
  } else if (role === 'doctor') {
    router.push('/doctor/doctor-info')
  } else {
    router.push('/login')
  }
}
</script>

<style scoped lang="scss">
.not-found-container {
  width: 100vw;
  height: 100vh;
  background-color: #f5f7fa;
  display: flex;
  align-items: center;
  justify-content: center;
}

.not-found-content {
  text-align: center;
  padding: 60px 50px;
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 20px 0 rgba(0, 0, 0, 0.08);
  width: 500px;
}

.error-code {
  font-size: 100px;
  font-weight: 700;
  color: #1989fa;
  margin-bottom: 20px;
  line-height: 1;
}

.title {
  font-size: 26px;
  font-weight: 600;
  color: #333;
  margin-bottom: 15px;
}

.desc {
  font-size: 16px;
  color: #666;
  margin-bottom: 35px;
  line-height: 1.6;
}

.btn-group {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.el-button {
  padding: 10px 30px;
  font-size: 16px;
}
</style>